﻿using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PmSoft.Utilities
{
    public static class ZipDecompress
    {
        public static bool DecompressFile(byte[] byZip, out byte[] byData, out string strMess)
        {
            byData = null;
            strMess = "";
            try
            {
                byData = Decompress(byZip);
                return true;
            }
            catch (Exception ex)
            {
                strMess = ex.Message;
                return false;
            }
        }

        private static byte[] Decompress(byte[] byData)
        {
            using MemoryStream stream = new MemoryStream(byData);
            using GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress);
            using MemoryStream memoryStream = new MemoryStream();
            int num = 1024;
            byte[] buffer = new byte[num];
            int num2 = 0;
            while ((num2 = gZipStream.Read(buffer, 0, num)) > 0)
            {
                memoryStream.Write(buffer, 0, num2);
            }
            return memoryStream.ToArray();
        }
    }
}
